﻿
@{
    Layout = "~/Views/Shared/_Layout.cshtml";

    var list = ViewBag.list as List<HttpReports.Web.Models.JobRequest>;
}

<style type="text/css">

    .table td, th {
        text-align: center;
        line-height: 24px !important;
    }
</style>

<div class="panel panel-default">

    <div class="panel-body" style="padding-left:30px;padding-right:30px;padding-top:30px;padding-bottom:30px">

        <div class="row">

            <div class="panel panel-default">
                <div class="panel-body" style="padding-bottom:20px">

                    <div class="col-sm-12" style="margin-bottom:30px;padding:0">

                        <div class="col-sm-3" style="padding-left:0">

                            <a style="min-width:120px;" href="/Home/AddMonitor" class="btn btn-primary btn-search">添加</a>

                        </div>

                    </div>

                    <table class="table table-striped table-bordered">
                        <thead>
                            <tr>
                                <th>任务标题</th>
                                <th>状态</th>
                                <th>监控频率</th>
                                <th>邮箱</th> 
                                <th>服务节点</th>
                                <th width="276">操作</th>
                            </tr>
                        </thead>
                        <tbody>

                            @foreach (var item in list)
                            {
                                <tr>
                                    <td>@item.Title</td>
                                    <td>

                                        @if (item.Status == 1)
                                        {
                                            <span style="width: 60px;padding-left:10px; padding-right:10px;margin-right: 8px;border-radius:0;" class="label label-success">运行中</span>
                                        }
                                        else
                                        {
                                            <span style="width: 60px;padding-left:10px; padding-right:10px;margin-right: 8px;border-radius:0;" class="label label-danger">已停止</span>
                                        }

                                    </td>
                                    <td>@item.CronLike</td>
                                    <td>@item.Email</td> 
                                    <td>@item.Node</td>

                                    <td>

                                        <a href="/Home/AddMonitor/@item.Id" style="margin:4px" type="button" class="btn btn-info btn-xs"><span class="glyphicon glyphicon-edit"></span> 编辑</a>

                                        @if (item.Status == 1)
                                        {
                                            <button style="margin:4px" type="button" onclick="stopJob(@item.Id)" class="btn btn-primary btn-xs"><span class="glyphicon glyphicon-off"></span> 停止</button>
                                        }
                                        else
                                        {
                                            <button style="margin:4px" type="button" onclick="startJob(@item.Id)" class="btn btn-success btn-xs"><span class="glyphicon glyphicon-play-circle"></span> 开启</button>
                                        }

                                        <button style="margin:4px" type="button" onclick="delJob(@item.Id)" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-remove-sign"></span> 删除</button>

                                    </td>
                                </tr>

                            }

                        </tbody>
                    </table>

                </div>
            </div>

        </div>

    </div>

</div>

<script>

    function startJob(Id) {

        confirm("确认要开启任务吗?", function () {

            $.ajax({

                url: "/Data/ChangeJobState/" + Id,
                success: function (result) {

                    alert("修改成功", function () {

                        location.reload();

                    });
                }
            })

        });

    }

    function stopJob(Id) {

        confirm("确认要停止任务吗?", function () {

            $.ajax({

                url: "/Data/ChangeJobState/" + Id,
                success: function (result) {

                    alert("修改成功", function () {

                        location.reload();

                    });
                }
            })


        });

    }

    function delJob(Id) {

        confirm("确认要删除任务吗?", function () {

            $.ajax({

                url: "/Data/DeleteJob/" + Id,
                success: function (result) {

                    alert("删除成功", function () {

                        location.reload();

                    });
                }
            }) 

        });
    }


</script>

